package com.battery.controller;

import com.battery.pojo.Sys_role;
import com.battery.service.Sys_roleService;
import com.battery.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "角色管理相关接口")

public class Sys_roleController {
    @Autowired

    Sys_roleService sys_roleService;

    @PostMapping("/Sys_role")
    @ResponseBody
    @CrossOrigin
    @ApiOperation("列出角色")
    public Result showSys_role(){
        return Result.ok().data("data",sys_roleService.findAllSys_role());
    }

    @PostMapping("/addSys_role")
    @ResponseBody
    @CrossOrigin
    @ApiOperation("添加角色")
    public Result addSys_role(Sys_role sys_role){
        return Result.ok().data("data",sys_roleService.addSys_role(sys_role));

    }

    @DeleteMapping("/deleteSys_Role/{role_id}")
    @ResponseBody
    @CrossOrigin
    @ApiOperation("删除角色")
    public Result deleteSys_role(@PathVariable("role_id") int role_id){

        return Result.ok().data("data",sys_roleService.removeSys_role(role_id));

    }

    @GetMapping("/searchSys_Role/{role_id}")
    @ResponseBody
    @CrossOrigin
    @ApiOperation("查找角色")
    public Result searchSys_role(@PathVariable("role_id") int role_id){

        return Result.ok().data("data",sys_roleService.searchSys_role(role_id));

    }

    @PutMapping("/changeSys_role")
    @ResponseBody
    @CrossOrigin
    @ApiOperation("修改角色")
    public Result changeSys_role( Sys_role  sys_role){

        return Result.ok().data("data",sys_roleService.changeSys_role(sys_role));

    }

}
